<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>系统额度</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">系统额度</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row">
                        <div class="layui-form" style="float:right;">
                            <div class="layui-form-item" style="margin:0;">
                                <div class="layui-input-inline">
                                    <input type="text" name="userId" id="userId" autocomplete="off" placeholder="账户ID"
                                           class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="createTimeStart" id="createTimeStart" autocomplete="off"
                                           placeholder="开始时间" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="createTimeEnd" id="createTimeEnd" autocomplete="off"
                                           placeholder="结束时间" class="layui-input">
                                </div>
                                <button id="search" class="layui-btn" data-type="reload">搜索</button>
                                <a class="layui-btn" lay-href="sys/quota/quota_add">新增系统点数</a>
                                <button class="layui-btn layui-btn-danger" id="confirmBtn" style="margin-left: 15px;">
                                    清空额度
                                </button>

                            </div>

                        </div>
                    </div>
                    <div style="margin-top: 10px;">
                        <blockquote class="layui-elem-quote" >
                            总储值点数:￥
                            <span style="color: #cc0000" id="totalPointsBlock"></span>
                        </blockquote>
                    </div>
                    <table id="XxPay_Mgr_User_dataAll" lay-filter="XxPay_Mgr_User_dataAll"></table>
                </div>

            </div>
        </div>
    </div>
</div>

<script type="text/html" id="xxpayBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="userRole">分配角色</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>



    layui.use(['admin', 'table', 'util','laydate'], function () {

        var $ = layui.$
            , admin = layui.admin
            , table = layui.table
            , element = layui.element
            , form = layui.form;

        var laydate = layui.laydate;


        laydate.render({
            elem: '#ID-laydate-calendar'
        });

        laydate.render({
            elem: '#createTimeStart'
        });

        laydate.render({
            elem: '#createTimeEnd'
        });


        admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/sys/quota/getAmountCount',
            data: {},
            success: function (res) {

                var totalPointsBlock = $('#totalPointsBlock');

                // 更新总储值点数的内容
                totalPointsBlock.text(res.data);

            }
        });

        element.render('breadcrumb', 'breadcrumb');

        var tplStatus = function (d) {
            if (d.status == 1) {
                return "<span style='color: green'>启用</span>";
            }
            return "<span style='color: red'>停止</span>";
        };

        var tplUserName = function (d) {
            if (d.isSuperAdmin == 1) {
                return d.userName + " <span class='layui-badge'>超管</span> ";
            }
            return d.userName;
        };

        //用户列表
        table.render({
            elem: '#XxPay_Mgr_User_dataAll'
            , url: layui.setter.baseUrl + '/sys/quota/get' //用户列表接口
            , where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            , id: 'tableReload'
            , page: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID'}
                , {field: 'amount', title: '金额'}
                , {field: 'usdt', title: 'USDT'}
                , {field: 'usdt_rate', title: 'USDT费率',}
                , {field: 'remark', title: '备注'}
                , {field: 'preChargePoint', title: '储值前点数'}
                , {field: 'postChargePoint', title: '储值后点数'}
                , {field: 'user_id', title: '账户id'}
                , {field: 'user_name', title: '账户名称'}
                , {field: 'ip', title: 'ip'}
                , {
                    field: 'createTime',
                    title: '时间',
                    templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'
                }
            ]]
            , skin: 'line'
        });
        // 搜索
        var $ = layui.$, active = {
            reload: function () {
                debugger
                let createTimeStart = $('#createTimeStart').val();
                let createTimeEnd = $('#createTimeEnd').val();
                let userId = $('#userId').val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        startTime: createTimeStart,
                        endTime: createTimeEnd,
                        user_id: userId
                    }
                });
            }
        };
        $('#search').on('click', function () {
            var type = $(this).data('type');

            active[type] ? active[type].call(this) : '';
        });



        $('.layuiAdmin-btns .layui-btn').on('click', function () {
            var othis = $(this)
                , thisEvent = othis.data('events')
                , type = othis.data('type');
            events[thisEvent] && events[thisEvent].call(this, othis, type);
        });



        $('#confirmBtn').on('click', function () {
            layer.confirm('确定执行清空操作吗？', {
                btn: ['确定', '取消'],
                btnAlign: 'c',
                title: '二次确认'
            }, function (index) {
                admin.req({
                    type: 'get',
                    url: layui.setter.baseUrl + '/sys/quota/delete',
                    data: {},
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg('删除成功', {
                                icon: 1
                            });
                            var totalPointsBlock = $('#totalPointsBlock');

                            // 更新总储值点数的内容
                            totalPointsBlock.text(0);
                            table.reload("tableReload");
                            layer.close(index); // 关闭确认框
                        }
                    }
                });
                // 在这里写点击确定后的操作

            });



        });

        // 渲染表单
        form.render();


    });
</script>